﻿using System;
using Component.Track;
using Component.Trains;
using TMPro;
using Tools;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Component.UI.View
{
    public class ResultView : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
    {
        [Header("↓点击事件")]
        [SerializeField] private IntEvent onClickEvent;
        [Header("结算界面按钮")]
        [SerializeField] private ResultViewBtn buttons;

        public TextMeshProUGUI ResultText => buttons.resultText;

        private void Start()
        {
            buttons.resetBtn.OnClickStart = ResetGame;
            buttons.quitBtn.OnClickFinished = GameOver;
        }
        private void OnEnable()
        {
            
        }

        public void OnPointerDown(PointerEventData eventData)
        {
            
        }

        public void OnPointerUp(PointerEventData eventData)
        {
            onClickEvent.Invoke(1);
        }

        private void ResetGame()
        {
            GameManager.Instance.ResetGame();
        }

        private void GameOver()
        {
            GameManager.Instance.GameOver();
        }

        public void InitGameOverView(Vector3 go, int runDay, int take)
        {
            CameraTools.CameraFollow(go, 1,Vector3.zero, delegate
            {
                CameraTools.CameraSizeFollow(5, 1);
            }, delegate
            {
                ViewManager.GetIntoStartView(ViewManager.ViewType.ResultView);
            });
        }
        

        [Serializable]
        public struct ResultViewBtn
        {
            public TextMeshProUGUI resultText;
            public UiButton scrollBtn;
            public UiButton resetBtn;
            public UiButton quitBtn;
        }
        
    }
}